//
//  QXRootViewController.m
//  JYQX
//
//  Created by Hayder on 2018/8/20.
//  Copyright © 2018年 Hayder. All rights reserved.
//

#import "HHRootViewController.h"
#import "HHNavigationController.h"
#import "UIImage+HHExtension.h"
#import "HHGlobalDefine.h"

@interface HHRootViewController ()

@property (nonatomic, strong) UIView *tabbarview;

@end

@implementation HHRootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //取消tabbr半透明
    self.tabBar.backgroundColor = [UIColor whiteColor];
    UIView *tabbarview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, HH_SCREEN_WIDTH, self.tabBarHeight)];
    [self.tabBar addSubview:tabbarview];
    self.tabbarview = tabbarview;
    [self.tabBar bringSubviewToFront:tabbarview];
}


- (UIButton *)addButtonWithFrame:(CGRect)frame
                           title:(NSString *)title
                           image:(UIImage *)image
                   selectedImage:(UIImage *)selectedImage
                          target:(id)target
                          action:(SEL)action
                  controllerName:(NSString *)cotrollerString
{
    UIButton *eventButton = [UIButton buttonWithUIProperty:HHButtonProperty.init()
                             .frame(frame)
                             .fontSize(10)
                             .title(title)
                             .selectedTitleColor(kThemeColor)
                             .titleColor(kGray_51)
                             .targetAction(target,action)];
    [eventButton setImage:image forState:UIControlStateNormal];
    [eventButton setImage:selectedImage forState:UIControlStateSelected];
    [self.tabbarview addSubview:eventButton];
    
    [eventButton layoutButtonWithEdgeInsetsStyle:HHButtonEdgeInsetsStyleTop imageTitleSpace:5];
    // 添加为tabbar控制器的子控制器
    UIViewController *childVc = [[NSClassFromString(cotrollerString) alloc] init];
    HHNavigationController *nav = [[HHNavigationController alloc] initWithRootViewController:childVc];
    [self addChildViewController:nav];
    
    return eventButton;
}

- (UIButton *)addButtonWithFrame:(CGRect)frame
                           title:(NSString *)title
                           image:(UIImage *)image
                   selectedImage:(UIImage *)selectedImage
                          target:(id)target
                          action:(SEL)action
                      controller:(UIViewController *)controller
{
    UIButton *eventButton = [UIButton buttonWithUIProperty:HHButtonProperty.init()
                             .frame(frame)
                             .fontSize(10)
                             .title(title)
                             .selectedTitleColor(kThemeColor)
                             .titleColor(kGray_51)
                             .targetAction(target,action)];
    [eventButton setImage:image forState:UIControlStateNormal];
    [eventButton setImage:selectedImage forState:UIControlStateSelected];
    [self.tabbarview addSubview:eventButton];
    
    [eventButton layoutButtonWithEdgeInsetsStyle:HHButtonEdgeInsetsStyleTop imageTitleSpace:5];
    // 添加为tabbar控制器的子控制器
    HHNavigationController *nav = [[HHNavigationController alloc] initWithRootViewController:controller];
    [self addChildViewController:nav];
    
    return eventButton;
}

@end
